<template>
  <!--  <RouterLimit />-->
  <a-row class="globalHeader" align="center" :wrap="false">
    <a-col flex="auto">
      <a-menu
        mode="horizontal"
        :default-selected-keys="['1']"
        @menu-item-click="doMenuClick"
      >
        <a-menu-item
          key="0"
          :style="{ padding: 0, marginRight: '38px' }"
          disabled
        >
          <div class="title-bar">
            <img src="../assets/giao.png" alt="" />
          </div>
        </a-menu-item>
        <a-menu-item v-for="item in visibleRouter" :key="item.path"
          >{{ item.name }}
        </a-menu-item>
      </a-menu>
    </a-col>
    <a-col flex="100px" class="login">
      <div>{{ store.loginUser.userName }}</div>
    </a-col>
  </a-row>
</template>

<script setup lang="ts">
import * as url from "url";
import { routes } from "@/router/routes";
import { useRouter } from "vue-router";
import { computed, onMounted, ref } from "vue";
import { useUserStore } from "@/store/user";
import checkAccess from "@/access/checkAccess";
import ACCESS_ENUM from "@/access/accessEnum";
import axios from "axios";
import { UserControllerService } from "../../generated";
import RouterLimit from "@/components/RouterLimit.vue";

//全局存储数据
const store = useUserStore();

//路由器
const router = useRouter();

const selectedKeys = ref(["/"]);

const visibleRouter = computed(() => {
  return routes.filter((item) => {
    if (item.meta?.hideInMenu) {
      return false;
    }
    return true;
    // return checkAccess(store.loginUser, item.meta?.webAccess as string);
  });
});

//向后端发请求
store.getLoginUser();

//NULL
router.afterEach((to, from, failure) => {
  selectedKeys.value = [to.path];
});

//编程式路由
const doMenuClick = (key: string) => {
  router.push({
    path: key,
  });
};
</script>

<style scoped>
.globalHeader {
  box-shadow: #666 2px 2px 10px;
}

.title-bar {
  width: 100px;
  border: 1px solid #000;
}

.title-bar img {
  width: 100%;
  height: 100%;
  display: flex;
}

.login {
  text-align: center;
}
</style>
